//
//  MeetingTableViewCell.m
//  HuaRun2
//
//  Created by admin on 17/8/29.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "MeetingTableViewCell.h"
#import "Com_MeetingModel.h"

@interface MeetingTableViewCell ()

@property (nonatomic, strong) UIView * backView;

//名字
@property (nonatomic, strong) UILabel * nameLab;

//时区Btn
@property (nonatomic, strong) UIButton * timeBtn;
//时区Btn
@property (nonatomic, strong) UIButton * locationBtn;

//时区
@property (nonatomic, strong) UILabel * timeLab;
//位置
@property (nonatomic, strong) UILabel * locationLab;

@end

@implementation MeetingTableViewCell

#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = RGBA(249, 249, 249, 1);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    
    [self.contentView addSubview:self.backView];
    [self.contentView addSubview:self.nameLab];

    [self.contentView addSubview:self.timeBtn];
    [self.contentView addSubview:self.timeLab];
    
    [self.contentView addSubview:self.locationBtn];
    [self.contentView addSubview:self.locationLab];
    
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView);
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.backView).offset(-kMargin10);
    }];
    
    [self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.nameLab.mas_bottom).offset(kMargin15);
        make.left.mas_equalTo(ws.nameLab);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];

    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeBtn);
        make.left.mas_equalTo(ws.timeBtn.mas_right).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView.mas_right).offset(-kMargin10);
    }];
    
    [self.locationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeLab.mas_bottom).offset(kMargin10/2);
        make.left.mas_equalTo(ws.nameLab);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];

    [self.locationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.locationBtn);
        make.left.mas_equalTo(ws.locationBtn.mas_right).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView.mas_right).offset(-kMargin10);
    }];

}

#pragma mark - getter setter 
- (void)setCom_MeetingModel:(Com_MeetingModel *)com_MeetingModel {
    _com_MeetingModel = com_MeetingModel;

    _nameLab.text = [NSString showSpaceStringWithStr:com_MeetingModel.name];
    _timeLab.text = [NSString stringWithFormat:@"%@\n%@-%@",
    [NSString showSpaceStringWithStr:com_MeetingModel.timezone],
                     [NSString showSpaceStringWithStr:com_MeetingModel.startTime],
                     [NSString showSpaceStringWithStr:com_MeetingModel.endTime]
                     ];
    
    _locationLab.text = [NSString showSpaceStringWithStr:com_MeetingModel.location];
    
}

- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    }
    return _nameLab;
}

- (UIView *)backView {
    if (!_backView) {
        self.backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

- (UILabel *)timeLab {
    if (!_timeLab) {
        self.timeLab = [UILabel new];
        _timeLab.textAlignment = NSTextAlignmentLeft;
        _timeLab.font = kGeneralFontSize;
        _timeLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _timeLab.numberOfLines = 0;
    }
    return _timeLab;
}

- (UILabel *)locationLab {
    if (!_locationLab) {
        self.locationLab = [UILabel new];
        _locationLab.textAlignment = NSTextAlignmentLeft;
        _locationLab.font = kGeneralFontSize;
        _locationLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    }
    return _locationLab;
}

- (UIButton *)locationBtn {
    if (!_locationBtn) {
        self.locationBtn = [UIButton new];
        [_locationBtn setBackgroundImage:[UIImage imageNamed:@"地址_1"]
                                forState:(UIControlStateNormal)];
    }
    return _locationBtn;
}
- (UIButton *)timeBtn {
    if (!_timeBtn) {
        self.timeBtn = [UIButton new];
        [_timeBtn setBackgroundImage:[UIImage imageNamed:@"时间_1"]
                                forState:(UIControlStateNormal)];
    }
    return _timeBtn;
}

@end
